﻿using furion.blog.Application;
using furion.blog.Application.Contracts;
using furion.blog.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using furion.blog.Application.KafkaMQ.Producers;
using Masuit.Tools.DateTimeExt;
using furion.blog.Domain.IRepositories;
using furion.blog.Domain.MySQL;

namespace furion.blog.Web.Entry.Controllers;

[AllowAnonymous]
public class HomeController : Controller
{
    private readonly ISystemService _systemService;
    private readonly AliSmsSendRecordProducer _aliSmsSendRecordProducer;
    private readonly IMessageRepository _messageRepository;


    public HomeController(ISystemService systemService,
        AliSmsSendRecordProducer aliSmsSendRecordProducer,
        IMessageRepository messageRepository
        )
    {
        _systemService = systemService;
        _aliSmsSendRecordProducer = aliSmsSendRecordProducer;
        _messageRepository = messageRepository;
    }

    public IActionResult Index()
    {
        ViewBag.Description = _systemService.GetDescription();
        var val = DateTime.Now.GetTotalNanoseconds();
        Console.WriteLine(val);
        return View();
    }

    [Route("test/createMqMessage")]
    public async Task<IActionResult> CreateMqMessage() {

        /*for (int i = 0, len = 1000; i < len; i++) {
            await _aliSmsSendRecordProducer.CreateAsync(new
            {
                Body = "信息" + i
            });
        }*/

        List<Message> one = new List<Message>();
        List<Message> two = new List<Message>();

        for (int i = 0, len = 1000; i < len; i++) {
            DateTime now = DateTime.Now;
            one.Add(new Message { 
              MessageId = IdUtil.Id(),
              FromUser = -1,
              ToUser = 321930473586556929,
              Content = "您好吗？？？Fuck You"+i,
              CreatedTime = now,
              Ts = now.GetTotalNanoseconds(),
              IsOpen = "No",
              IsDelete = "No",
            });
            two.Add(new Message
            {
                MessageId = IdUtil.Id(),
                FromUser = -1,
                ToUser = 321930473586556929,
                Content = "您好吗？？？Thank You" + i,
                CreatedTime = now,
                Ts = now.GetTotalNanoseconds(),
                IsOpen = "Yes",
                IsDelete = "No",
            });
        }

        //await this._messageRepository.SaveBatch(one);
        //await this._messageRepository.SaveBatch(two);

        return new OkObjectResult(ResultUtil.Success());
    }

}
